<template>
  <div>
      <el-upload class="avatar-uploader"
					drag :show-file-list="false"
					:action="qiniuUrl"	:http-request = coverUpload>
					<img v-if="cover" :src="cover" class="avatar">
					<i v-else class="el-icon-plus avatar-uploader-icon"></i>
				</el-upload>
        </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data(){
      return{
          cover:''
      }
  },
  methods:{
		coverUpload(params){
			this.$store.commit('setType','cover')
			this.$qiniu(params)
		}
  },
  computed: {
			//这里需要把store动态的数据放到computed里面才会同步更新视图
			getFiles(){
				console.log(this.$store.state.files)
                return this.$store.state.files
            },
			getCover(){
				return this.$store.state.cover
			}
		},
		watch:{
			getFiles(newFile){
				if(newFile.file_type == 'cover')
					this.cover = newFile.url
				console.log(this.cover)
                this.$store.commit('setCover',this.cover)
                this.$forceUpdate()
			},
			getCover(newUrl){
				this.cover = newUrl
                this.$forceUpdate()
			}
		}
}
</script>

<style>
</style>
